<?php
require_once 'settings.php';
class DBConnection {
		private $myMysqli = NULL;
		public function connect(){
			$this->myMysqli = new mysqli(Settings::DBHOST, Settings::DBUSER, Settings::DBPASSWORD, Settings::DATABASE);
			// Set charset before any queries
			$this->myMysqli->set_charset("utf8");
			// Check connection
			if ($this->myMysqli->connect_errno){
				echo "Connect failed: $this->myMysqli->connect_error";
				return false;
			}
			return true;
		}
		public function close(){
			echo "Connection close";
			$this->myMysqli->close();
		}
		
		public function prepare($sql){
			// Prepare and return sql statement
			$stmt = $this->myMysqli->prepare($sql);
			if($stmt === FALSE){
				echo "Prepare of '$sql' failed" . $this->myMysqli->error;
				return false;
			}
			return $stmt;
		}
}
